<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<script type="text/javascript">
	var form_url = base.contextPath+"/sysmgr/company/add.do" ;
	var company, area_treebox, u1 ;
	var simple = [[
		'fontset', '|', 'forecolor', 'backcolor',
		'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify','|', 
		'emotion', 'scrawl', '|', 'snapscreen', 'insertimage', 'attachment', '|', 'source', 'preview'
	]];
	$(function() {
		company = $("#company").combotree({
			url : base.contextPath+"/sysmgr/company/doNotNeedAuth_tree.do",
			idFiled:'pid', textFiled:'name', editable: false,
			lines:true, autoShowPanel: true
	    });
		area_treebox = $("#area_treebox").combotree({
			url: base.contextPath+"/sysmgr/area/treegrid_areas.do", required: true,autoShowPanel: false,
			onSelect: function(node) {
				$("input[name=area]").val(node.areaName) ;
			} 
	    });  
		
		u1 = new UE.ui.Editor({ toolbars : simple });
		u1.render('u1');
		u1.addListener('ready', function(e) {
			//编辑，加载表单数据
			if($('input[name=id]').val().length > 0) {
				form_url = base.contextPath+"/sysmgr/company/edit.do" ;
				$.post(base.contextPath+"/sysmgr/company/get.do", {id:$('input[name=id]').val()}, function(result) {
					if (result.id != undefined) {
						$('form').form('load', {
							'id' : result.id,
							'name' : result.name,
							'code' : result.code,
							'tel' : result.tel,
							'post_code' : result.post_code,
							'site' : result.site,
							'addr' : result.addr,
							'fax' : result.fax,
							'pid' : result.pid,
							'area': result.area,
							'remark' : result.remark
						});
						u1.setContent(result.remark);
						area_treebox.combotree("setValue", result.area) ;
					}
				}, 'json');
			}
		});
		
	});
	
	//提交表单数据
	var submitNow = function($d, $t) {
		$.post(form_url, $("#form").form("getData"), function(result) {
			if (result.status) {
				$t.tree('reload') ;
				alertify.success(result.msg);$.easyui.loaded(); $d.dialog("close") ;
			} else {
				$.easyui.loaded();$.messager.alert("错误", result.msg, "error");
			}
		}, 'json');
	};
	
	//验证表单
	var submitForm = function($d, $t) {
		if($('#form').form('validate')) {
			$.easyui.loading({ msg: "数据提交中，请稍等..." });
			submitNow($d, $t) ;
		}
	};
	
	
</script>
<form id="form" class="easyui-form form_container">
	<input type="hidden" name="id" value="${id}" />
	<input type="hidden" name="modifyName" value="${USER_SESSION.truename}" />
	<table class="tableform">
		<tr>
			<th>机构名称：</th>
			<td><input name="name" class="easyui-validatebox s300" type="text" data-options="required: true,prompt: '单位名称'" /></td>
		</tr>
		<tr>
			<th>机构代码：</th>
			<td><input name="code" class="easyui-validatebox s300" type="text" data-options="prompt: '机构代码'" /></td>
		</tr>
		<tr>
			<th>机构电话：</th>
			<td><input name="tel" class="easyui-validatebox s300" type="text" /></td>
		</tr>
		<tr>
			<th>机构传真：</th>
			<td><input name="fax" class="easyui-validatebox s300" type="text" /></td>
		</tr>
		<tr>
			<th>邮政编码：</th>
			<td><input name="post_code" class="easyui-validatebox s300" type="text" /></td>
		</tr>
		<tr>
			<th>官方网址：</th>
			<td><input name="site" class="easyui-validatebox s300" type="text" /></td>
		</tr>
		<tr>
			<th>联系地址：</th>
			<td><input name="addr" class="easyui-validatebox s300" type="text" /></td>
		</tr>
		<tr>
			<th>上级机构：</th>
			<td><input id="company" name="pid" style="width:308px;height:30px;" data-options="prompt: '分支机构'" /><a onClick="company.combotree('setValue','');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_clear'"></a></td>
		</tr>
		<tr>
			<th>所在区域：</th>
			<td>
				<input name="area" value="" type="hidden"/>
				<input id="area_treebox" style="width:308px;height:30px;" /><a onClick="area_treebox.combotree('setValue','');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_clear'"></a>
			</td>
		</tr> 
		<tr>
			<th>简介：</th>
			<td>
				<textarea id="u1" name="remark" style="width:565px;height:320px;"></textarea>
			</td>
		</tr>
	</table>
</form>

